package com.polymathcoder.dpastry.api.pastry;

import com.polymathcoder.dpastry.dPastry;

/**
 * Created by IntelliJ IDEA.
 * User: Drew
 * Date: Jul 5, 2010
 * Time: 12:00:01 AM
 * To change this template use File | Settings | File Templates.
 */
public interface Node {
    public Endpoint registerService(Service service, String instance);

    /**
     * Returns the Id of this node
     *
     * @return This node's Id
     */
    public Id getId();

    /**
     * Returns a factory for Ids specific to this node's protocol.
     *
     * @return A factory for creating Ids.
     */
    public IdFactory getIdFactory();

    /**
     * Returns a handle to the local node. This node handle is serializable, and
     * can therefore be sent to other nodes in the network and still be valid.
     *
     * @return A NodeHandle referring to the local node.
     */
    public NodeHandle getLocalNodeHandle();

    /**
     * Returns the environment.  This allows the nodes to be virtualized within the JVM
     *
     * @return the environment for this node/app.
     */
    public dPastry getPastryEnvironment();

    /**
     * Same as register application, but returns an unregistered Endpoint.  This allows
     * the application to finish initialization that may require the endpoint
     * before it receives messages from the network and notification of changes.
     * <p/>
     * When then application is ready, it must call endpoint.register() to receive messages.
     *
     * @param service
     * @param instance
     * @return
     */
    public Endpoint buildEndpoint(Service service, String instance);

    /**
     * For debugging: print the internal routing state of the Node.
     *
     * @return
     */
    public String printRouteState();
}
